# coding=utf-8
from rest_framework.decorators import APIView
from rest_framework.response import Response

from ali_pay import alipay


class AliAsynchronousCallback(APIView):
    def get(self, request, **kwargs):
        data = request.query_params.copy()
        data_copy = {k: data[k] for k in data}
        print(data_copy)
        signature = data_copy.pop("sign")
        success = alipay.verify(data_copy, signature)
        return Response(success)

    def post(self, request, **kwargs):
        data = request.data.copy()
        signature = data.pop("sign")
        success = alipay.verify(data, signature)
        return Response(success)
